function waitForPlugin(sender, args)
{
    if(host == null)
    {
        host = sender.content;
    }
    
    if(host.actualWidth == 0)
    {
        window.setTimeout("waitForPlugin()", 100);
    }
    else
    {
        init();
    }
}

function init() {
    //window.setTimeout("init()", 1000);
    
    host.onFullScreenChange = controlSizeChanged;

    dragCanvas = host.findName("dragCanvas");
    dragCanvas.Width = host.ActualWidth;
    dragCanvas.Height = host.ActualHeight;
    
    photoCanvas = host.findName("photoCanvas");
    
    dragEnabled = false;
    dragStartX = 0;
    dragStartY = 0;
    
    zoomedIn = false;
    
    positionLegend();
    positionControls();
    hideControls();
    
    host.findName("btnPrevious").Opacity = 0;
    host.findName("btnNext").Opacity = 0;
    host.findName("btnPause").Opacity = 0;

    loadData();
}

function root_KeyDown(sender, keyEventArgs)
{
    if(zoomedIn)
    {
        var left = 30;
        var right = 48;
        switch(keyEventArgs.key)
        {
            case left:
                if(currentImageNr > 0)
                    move(-1);
                break;
            case right:
                if(currentImageNr < photoCanvas.Children.Count - 1)
                    move(1);
                break;
        }
    }
}

function controlSizeChanged()
{
    dragCanvas.Width = host.ActualWidth;
    dragCanvas.Height = host.ActualHeight;
    
    positionLegend();
    positionControls();
    
    if(slideshow)
        btnPauseClick();
    
    if(zoomedIn)
        zoomOutStep1();
}

function btnFullscreenClick(sender, eventArgs) {
	host.fullscreen = !host.fullscreen;
}

